// pages/search/search.js
const app = getApp()
var imageUtil = require('../../utils/Constant.js')
var dateUtils = require('../../utils/Date.js')
Page({
    /**
     * 组件的属性列表
     */
    properties: {

    },
    // 页面加载
    onShow() {

    },
      // 去详情页
  toDetail(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../detail/detail?id=' + id,
    })
  },
    // 搜索

    searchResult(e) {
        console.log(e)
        var keyword = e.detail
        var that = this
        app.http.post('tt/article/getArticleByKeyWord', {
            keyWord: keyword,
            timestamp: ""
        }).then(res => {
            console.log(res)
            var list = res.data
            if (list) {
                for (var i = 0; i < list.length; i++) {
                    list[i].img = imageUtil.baseUrl + list[i].img
                    list[i].time = list[i].createTime // 方便根据业务时间戳进行分页
                    list[i].createTime = dateUtils.relativeTime(list[i].createTime)
                }
            }
            that.setData({
                articleList: res.data
            })
        })
    },
    /**
     * 组件的初始数据
     */
    data: {
        articleList: [],
        flag: true // 骨架屏
    },

    /**
     * 组件的方法列表
     */
    methods: {

    }
})